package com.zbdx.service.impl;

import com.zbdx.dao.IGoodsDao;
import com.zbdx.dao.impl.GoodsDaoImpl;
import com.zbdx.domain.product;
import com.zbdx.service.IGoodsService;

import java.sql.SQLException;
import java.util.List;

public class GoodsServiceImpl implements IGoodsService {
    private IGoodsDao goodsDao = new GoodsDaoImpl();
    @Override
    public boolean addGoods(product product) throws SQLException {
        int res = goodsDao.insert(product);
        System.out.println("res:"+res);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean modifyGoods(product product) throws SQLException {
        int res = goodsDao.update(product);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public List<product> findAll() throws SQLException {
        List<product> products = goodsDao.selectAll();
        return products;
    }

    @Override
    public List<product> findByType(String PType) throws SQLException {
        List<product> products = goodsDao.selectByType(PType);
        return products;
    }

    @Override
    public List<product> search(String PName, String PType, String Id) throws SQLException {
        List<product> products = goodsDao.search(PName,PType,Id);
        return products;
    }

    @Override
    public product findById(int PId) throws SQLException {
        product product = goodsDao.selectById(PId);
        return product;
    }

    @Override
    public boolean removeById(int PId) throws SQLException {
        int res = goodsDao.deleteById(PId);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeSelect(List<Integer> ids) throws SQLException {
        int res = goodsDao.removeSelect(ids);
        if(res > 0){
            return true;
        }
        return false;
    }


}
